package com.youku.utils
{
   import flash.events.EventDispatcher;
   import flash.utils.Timer;
   import flash.net.NetStream;
   import flash.events.TimerEvent;
   import com.youku.events.BasePlayerEvent;
   
   public class DelayTimer extends EventDispatcher
   {
      
      public function DelayTimer(param1:NetStream, param2:Number) {
         super();
         this._ns = param1;
         this._num = param2;
         this._delayTimer = new Timer(50,0);
         this._delayTimer.addEventListener(TimerEvent.TIMER,this.checkBuffer);
      }
      
      public static const DELAY_EVENT:String = "delayevent";
      
      private var _delayTimer:Timer;
      
      private var _start:Number;
      
      private var _end:Number;
      
      private var _ns:NetStream;
      
      private var _num:Number;
      
      public function start() : void {
         this._start = new Date().time;
         this._delayTimer.start();
      }
      
      public function stop() : void {
         this._delayTimer.stop();
      }
      
      private function checkBuffer(param1:TimerEvent) : void {
         if(this._ns.bufferLength < this._ns.bufferTime)
         {
            return;
         }
         this._delayTimer.stop();
         this._end = new Date().time;
         var _loc2_:Number = this._end - this._start;
         this.dispatchEvent(new BasePlayerEvent(DELAY_EVENT,
            {
               "num":this._num,
               "dt":_loc2_
            }));
      }
   }
}
